package org.jiajie.coffeecodes.demo.jvm.wf;

/**
 * @author jie
 * @date 2022/4/1 9:50 PM
 */
public class Client {
    public static void main(String[] args) {
        Salad salad = new Salad(new Apple("red fuji"));
        // by WeakReference.get() get the object of Apple
        System.out.println("Apple:" + salad.get());
        System.gc();
        try {
            //休眠一下，在运行的时候加上虚拟机参数-XX:+PrintGCDetails，输出gc信息，确定gc发生了。
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        // 如果为空，代表被回收了
        if (salad.get() == null){
            System.out.println("Clear Apple.");
        }
    }
}
